<?php
namespace App\Http\Controllers\Business\Shop\V1\ShopLog;

use App\Models\ShopUser;
use Log;
use Illuminate\Support\Facades\Redis;
use App\Models\AdminUser;
use App\Models\City;
use App\Models\Shop;
use App\Models\ShopCheck;
use App\Models\ShopContract;
use Auth;
use Exception;
use App\Models\Province;

class ShopLog {
    //内容：商家代码、商家名称、商家状态、商务人员、最新操作时间 、操作类型, 来源
    //类型：提交审核、审核不通过、上架、取消今日翻倍花、开通今日翻倍花、下架、续签、修改维护人、修改收款帐号、修改商家登录号码、资料更新、修改翻倍日、删除，来源（商家版，后台）
    /*
     * 类型：
          'new':首次上线
          'downshelf':下架
          'upshelf':上架
           'cancel_doubleday': 取消今天翻倍日
           'open_doubleday':开通今天翻倍日
           'customer_check_pass': 客服审核通过
           'update_shop':修改商家信息
           'update_shop_maintainer':修改维护人
           'update_shop_oldmaintainer':修改原系统维护人
           'update_shop_mobile': 修改商家登录账号
           'update_shop_contract': 修改商家续约
           'update_shop_account': 修改商家收款账号
            'shop_set_doublecalendar':(商家)修改商家翻贝日期
     * */


    //用户简单操作 写入商家日志（type 上下架）
    public static function writeShopLog($shopUserId, $shopId, $type, $withholdType, $reason, $remark) {
        if(!$shopUserId||!$reason || !$shopId) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        $contractorId = ShopContract::where('shopid', $shopId)->orderBy('id', 'desc')->pluck('contractorid')->first();
        if($contractorId) {
            $contractorName = AdminUser::where('id', $contractorId)->pluck('realname')->first();
        } else {
            $contractorId = 0;
            $contractorName = '';
        }
        $maintainerId = Shop::where('id', $shopId)->orderBy('id', 'desc')->pluck('maintainerid')->first();
        if($maintainerId) {
            $maintainerName = AdminUser::where('id', $maintainerId)->pluck('realname')->first();
        } else {
            $maintainerId = 0;
            $maintainerName = '';
        }
        $shopCheck = ShopCheck::create([
            'shopid' => $shopId,
            'type' => $type,
            'withholdtype' => $withholdType,
            'reason' => $reason,
            'remark' => $remark,
            'contractorid' => $contractorId,
            'contractorname' => $contractorName,
            'maintainerid' => $maintainerId,
            'maintainername' => $maintainerName,
            'adminid' => $shopUserId,
        ]);
        $shopCheck->save();
        return ['status'=>'success', 'message'=>'写入成功'];
    }
}